<template>
  <div class="page-main" v-title data-title="酱油成品主数据">
    <home-nav :userData="userinfo"></home-nav>
    <div class="banner"><span>成品主数据</span></div>
    <div class="container">
      <div class="container-bg">
        <div class="header">
          <a-row type="flex" justify="space-between" align="middle">
            <a-col :xl="{ span: 11 }" :lg="{ span: 11 }">
              <a-button class="hte-btn add-btn" type="primary" icon="plus" @click="gotoDetail('/clearJy/finished/info')">新增</a-button>
              <a-button class="hte-btn" @click="handAction('upd')">修改</a-button>
              <a-button class="hte-btn" @click="handlePostExportXls('成品主数据')">导出</a-button>
              <a-button class="hte-btn" type="danger" @click="handAction('del')">删除</a-button>
              <a-button class="hte-btn" @click="refresh">刷新</a-button>
            </a-col>
            <a-col :xl="{ span: 9 }" :lg="{ span: 13 }" class="input-ground">
              <a-input-group compact>
                <a-select v-model="searchField" @change="changeKeywordType">
                  <a-select-option value="prodNo"> 成品编号 </a-select-option>
                  <a-select-option value="prodName"> 成品名称 </a-select-option>
                </a-select>
                <a-input-search
                  v-if="searchField == 'prodNo'"
                  v-model="queryParam.prodNo"
                  @search="doSearch"
                  allowClear
                  placeholder="请输入关键词检索"
                />
                <a-input-search
                  v-if="searchField == 'prodName'"
                  v-model="queryParam.prodName"
                  @search="doSearch"
                  allowClear
                  placeholder="请输入关键词检索"
                />
              </a-input-group>
              <a-button class="hte-btn del-btn" @click="visibleModel = true">高级查询</a-button>
            </a-col>
          </a-row>
        </div>
        <div class="content">
          <a-table
            class="hte-table-content"
            :scroll="{ x: 1500 }"
            :columns="columns"
            :data-source="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            rowKey="id"
            size="middle"
            @change="handleTableChange"
          >
            <template slot="swicth" slot-scope="text">
              <span>{{ text ? '是' : '否' }}</span>
            </template>
            <template slot="prodNo" slot-scope="text, record">
              <span class="clickspan" @click="gotoDetail('/clearJy/finished/info?id='+ record.id)">{{ text }}</span>
            </template>
          </a-table>
        </div>
      </div>
    </div>
    <a-back-top class="backtodom" />
    <!-- 高级查询 -->
    <advanced-search
      :dataForm.sync="queryParam"
      :visible="visibleModel"
      ref="advanced"
      :formCol="queryParamCol"
      @ok="callBackResult"
      @reset="resetResulte"
      @close="closeResulte"
    >
    </advanced-search>
  </div>
</template>
<script>
import Vue from 'vue'
import { getAction, postAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListSearchMixin'
import { ClearLibMixin } from '@/mixins/ClearLibMixin'
import { USER_INFO } from '@/store/mutation-types'
import {codeInfoList} from '@/api/codeInfo'
export default {
  name: 'BurdenList',
  mixins: [ClearLibMixin,JeecgListMixin],
  components: {
    HomeNav: () => import('@/components/layouts/HomeNav'),
    AdvancedSearch: () => import('@/components/tools/AdvancedSearch'),
  },
  data() {
    return {
      disableMixinCreated:true,
      userinfo: {
        info: this.$store.getters.userInfo,
        module: 'FinishedList',
      },
      currUser: Vue.ls.get(USER_INFO).username,
      columns: [
        {
          title: '品种编号',
          dataIndex: 'prodNo',
          width: 120,
          align: 'center',
          scopedSlots: { customRender: 'prodNo' },
        },
        { title: '品种名称', dataIndex: 'prodName', width: 180, align: 'center' },
        { title: '品种类型', dataIndex: 'prodTypeName', width: 120, align: 'center',},
        { title: '品种大类', dataIndex: 'prodClassName', width: 120, align: 'center'},
        { title: '配料表', dataIndex: 'materialNames', width: 180, align: 'center'},
        { title: '有机属性', dataIndex: 'organic', width: 100, align: 'center', scopedSlots: { customRender: 'swicth' }},
        { title: '加严属性', dataIndex: 'stricture', width: 100, align: 'center', scopedSlots: { customRender: 'swicth' }},
        { title: '备注', dataIndex: 'remark', width: 200, align: 'center', ellipsis: true },        
        { title: '创建人', dataIndex: 'createUserName', width: 120, align: 'center' },
        { title: '创建时间', dataIndex: 'createTime', width: 180, align: 'center' },        
      ],
      url: {
        list: '/hteWashProduct/page', // 搜索
        delBatch: '/hteWashProduct/delBatch', // 删除
        exportXlsUrl: '/hteWashProduct/export', // 导出        
      },
      // 高级查询
      visibleModel: false,
      searchField: 'prodNo',
      queryParam: {
        orderNo: '',
        orderName: '',
      },
      queryParamCol: [
        { type: 'input', model: 'prodNo', label: '成品编号' },
        { type: 'input', model: 'prodName', label: '成品名称' },
        // { type: 'select', model: 'prodType', label: '品种类型', dictList: [
        //     {name: '半成品',code: '1'},
        //     {name: '成品',code: '2'},            
        //   ],
        // },
        // { type: 'select', model: 'displayClass', label: '品种大类', dictList: [
        //     {name: '酱油',code: '1'},
        //     {name: '酱油',code: '2'},
        //     {name: '料酒',code: '3'},
        //     {name: '醋',code: '4'},
        //     {name: '鸡精',code: '5'},
        //   ],
        // },
      ],
    }
  },
  created(){
     this.loadData(1);

  },
  mounted() {
  },
  methods: {
    refresh() {
      this.loadData()
    },
    doSearch() {
      this.loadData(1)
    },
    changeKeywordType() {
      if (this.searchField == 'prodNo') {
        this.$set(this.queryParam, 'prodName', '')
      } else {
        this.$set(this.queryParam, 'prodNo', '')
      }
    },
    /**
     * 高级搜索
     */
    callBackResult() {
      this.visibleModel = false
      this.doSearch()
    },
    closeResulte() {
      this.visibleModel = false
    },
    resetResulte() {
      this.queryParam = {}
    },
    /**
     * 操作
     */
    handAction(type, id) {
      switch (type) {
        case 'del':
          // 删除，可多选
          const that = this
          if (this.selectedRowKeys.length == 0) {
            this.$message.warning('请选择至少一条数据！')
            return
          }
          this.$confirm({
            title: '确认删除',
            content: '请确认是否删除此信息?',
            onOk: function () {
              postAction(that.url.delBatch, that.selectedRowKeys).then((res) => {
                if (res.code == 200) {
                  that.$message.success('删除成功')
                  that.loadData();
                } else {
                  that.$message.warning('删除失败:' + res.message)
                }
              })
            },
          })
          break
        case 'upd':
          // 修改
          if (this.selectedRowKeys.length != 1) {
            this.$message.warning('请选择一条数据！')
            return
          }          
          this.gotoDetail(`/clearJy/finished/info?id=${this.selectionRows[0].id}`)          
          break
        default:
          break
      }      
    },
    gotoDetail(url){
      let routeUrl = this.$router.resolve({
        path: url
      });
      window.open(routeUrl.href, '_blank');
    },
  },
}
</script>

<style lang="less" scoped>
@import '~@assets/less/hte-main.less';
@import '~@views/library/clearSoln/index.less';
</style>
